<?php
/**
 * Created by PhpStorm.
 * User: beich
 * Date: 2019/1/29
 * Time: 12:36
 */

//header("Content-Type: text/json; charset=utf8");
Session_start();
$servername = "localhost";
$username = "zjwdb_6150221";
//$username = "root";
$password = "Hua1995.db6150221";
//$password = "root";
$dbname = "zjwdb_6150221";

$con = new mysqli($servername, $username, $password, $dbname);
if (!$con)
    die(json_encode(array('code' => -1, 'msg' => 'sql connect error', 'data' => array('error' => mysqli_connect_error()))));

class Response
{
    public static function ulLis($con)
    {
        $Uls = '<ul> 
        <li class="li_active"><a href="index.html">HOME</a></li> 
        <li><a href="doc.html">DOCUMENT</a></li> 
        <li><a href="about.html">ABOUT US</a></li> 
        <li><a href="http://www.heanny.cn">BLOG</a></li> 
        <li><a href="pricing.html">PRICING</a></li> 
        <li><a href="login.html">LOGIN</a></li> 
        </ul>';
        return $Uls;

    }

    public static $footer = '<footer class="footer-area bg-white">
        <div class="container">
        <ul class="footer-inner">
        <li>Links : <a href="http://www.heanny.cn">Heanny Blog</a></li>
        <li></li>
        <li><a href="mailto://info@example.com">lzh@heanny.cn</a></li>
        <li>Copyright &copy; 2008 - 2018 <a href="http://www.heanny.cm/" target="_blank" title="Heanny Blog">Heanny Doc System</a> | 冀ICP备18027130号 </li>
        </ul>
        </div>
        </footer>';

    public static function json($code = -1, $msg = '', $data = array())
    {
        $result = array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        );
        echo json_encode($result);
        exit;
    }

    public static function getDatas($sql, $con)
    {
        $con->query("SET NAMES utf8");
        $rs = $con->query($sql);
        $c = array();
        while ($r = $rs->fetch_object()) {
            array_push($c, $r);
        }
        return $c;
    }

    public static function getData($sql, $con)
    {
        $con->query("SET NAMES utf8");
        $rs = $con->query($sql);
        $r = $rs->fetch_object();
        return $r;
    }

    public static function putData($sql, $con)
    {
        $con->query("SET NAMES utf8");
        $rs = $con->query($sql);
        return $rs;
    }

    public static function create_password($pw_length)
    {
        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $chars = '0123456789';
        $password = '';
        for ($i = 0; $i < $pw_length; $i) {
            // 这里提供两种字符获取方式
            // 第一种是使用 substr 截取$chars中的任意一位字符；
            // 第二种是取字符数组 $chars 的任意元素
            // $password .= substr($chars, mt_rand(0, strlen($chars) – 1), 1);
            $password .= $chars[mt_rand(0, strlen($chars) - 1)];
        }
        return $password;
    }
}

?>